package com.bolins.examples.subspringside.mongodb;

import java.io.File;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

import org.bson.types.ObjectId;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.gridfs.GridFS;
import com.mongodb.gridfs.GridFSDBFile;

/**
 * Mongod 基本操作接口
 * 
 * @author liuys
 * 
 */
public interface MongodService {

	public DBCollection getCollection();

	/**
	 * insert data Map into mongodb, the key in Map is mapped DBCollection's key
	 * in mongodb
	 * 
	 * @param map
	 */
	public void insert(Map<String, Object> map);

	/**
	 * insert into mongodb with Restrictions
	 * 
	 * @param rests
	 */
	public void insert(Restrictions rests);

	/**
	 * batch insert Map into mongodb
	 * 
	 * @param list
	 */
	public void insertBatchWithMap(List<Map<String, Object>> list);

	public void insertBatchWithRestrictions(List<Restrictions> list);

	/**
	 * delete by the data in map
	 * 
	 * @param map
	 */
	public void delete(Map<String, Object> map);

	public void delete(Restrictions rests);

	public void deleteBatchWithMap(List<Map<String, Object>> list);

	public void deleteBatchWithRestrictions(List<Restrictions> list);

	public long getCollectionCount();

	public long getCount(Map<String, Object> map);

	public List<Map<String, Object>> find(Map<String, Object> map);

	public List<Map<String, Object>> find(Restrictions rests);

	public void update(Map<String, Object> setFields,
			Map<String, Object> whereFields);

	public void update(Restrictions setFilds, Restrictions whereFields);

	public List<Map<String, Object>> findAll();

	public Map<String, Object> getById(String id);

	/**
	 * save inputstream into mongodb
	 * 
	 * @param is
	 * @param filename
	 */
	public void saveFile(InputStream is, String fileName);

	/**
	 * save file into mongodb
	 * 
	 * @param file
	 * @param filename
	 */
	public void saveFile(File file, String fileName);

	public void saveFile(byte[] bytes, String fileName);

	public List<GridFSDBFile> findFilesByName(String fileName);

	public InputStream getFileInputStream(String fileName);

	public GridFSDBFile findFirstFile(Map<String, Object> map);

	public GridFSDBFile findFirstFile(Restrictions rests);

	public List<String> getDBNames();

	public long getFileCount();

	public List<GridFSDBFile> getAllFiles();

	public void removeFile(String fileName);

	public void removeFile(BasicDBObject object);

	public void removeFile(ObjectId id);

	public void removeAllFile();

	public GridFS getGridFS();

	public String getDBName();

	public void setDBName(String db);

	public String getCollectionName();

	public void setCollectionName(String coll);

	public DB getDB();

	public void setDB(DB db);
}
